<?php

namespace core\traits;

use support\Response as SupportResponse;
use support\View;

trait HomeView
{

    public function view(string $tempfile = '', array $var = []): SupportResponse
    {
        $site = now_site();
        $staticpath = '/static/home/' . $site['ident'] . '/' . ($site['theme'] == '' ? '' : $site['theme'] . '/');
        $theme = $site['theme'] == '' ? '' : $site['theme'];
        $templatepath = base_path() .
            '/template/home/' .
            $site['ident'] .
            '/' .
            ($theme == '' ? '' : $theme . '/');


        View::assign('staticpath', $staticpath);
        View::assign('templatepath', $templatepath);
        View::assign('siteinfo', $site);

        $controller = get_controller();
        $controller_arr = explode('/', $controller);
        $template = is_home_page() ? 'index' : $controller_arr[1] . '/' . ($tempfile == '' ? get_action() : rtrim($tempfile, '.php'));
        $plugin = get_plugin();
        return view(
            '/template/home/' .
                $site['ident'] .
                '/' .
                ($plugin == '' ? '' : $plugin . '/') .
                ($theme == '' ? '' : $theme . '/') .
                $template,

            $var,
            '',
            ''
        );
    }
}
